<?php

use Phalcon\Forms\Form;
use Phalcon\Forms\Element\Text;
use Phalcon\Forms\Element\Password;
use Phalcon\Forms\Element\Hidden;
use Phalcon\Validation\Validator\PresenceOf;

class PortalForm extends Form
{

    /**
     * Initialize the products form
     *
     * model取出来的密码要和原始的密码一直，
     * 然后在判断2次新密码是否一致 ，
     * 一致就把新密码存到数据库。
     */
    public function initialize($entity = null, $options = array())
    {
        if (!isset($options['edit'])) {
            $element = new Text("id");
            $this->add($element->setLabel("Id"));
        } else {
            $this->add(new Hidden("id"));
        }

        $name = new Text("name");
        $name->setLabel("用户名");
        $name->setFilters(array('striptags', 'string'));
        $name->addValidators(array(
            new PresenceOf(array(
                'message' => '用户名是必填项'
            ))
        ));
        $this->add($name);

        $password = new Password("password");
        $password->setLabel("原始密码");
        $password->setFilters(array('striptags', 'string'));
        $password->addValidators(array(
            new PresenceOf(array(
                'message' => '原始密码是必填项'
            ))
        ));
        $this->add($password);

        $newPassword = new Password("newPassword");
        $newPassword->setLabel("新密码");
        $newPassword->setFilters(array('striptags', 'string'));
        $newPassword->addValidators(array(
            new PresenceOf(array(
                'message' => '新密码是必填项'
            ))
        ));
        $this->add($newPassword);

        $checkPassword = new Password("checkPassword");
        $checkPassword->setLabel("确认新密码");
        $checkPassword->setFilters(array('striptags', 'string'));
        $checkPassword->addValidators(array(
            new PresenceOf(array(
                'message' => '确认新密码是必填项'
            ))
        ));
        $this->add($checkPassword);


    }
}